<meta charset="utf-8"> 

<?php

class pagination extends DB {

    public function Phantrang() {
        $baitren_mottrang = 10;
        if (!isset($_GET['page'])) {
            $page = 1;
        } else {
            $page = (int) $_GET['page'];
        }
        $sodu_lieu = mysql_num_rows(mysql_query("SELECT * FROM works ")) or die(mysql_error());
        $max = 94;
        $huuha = $page * $baitren_mottrang;
        $result = mysql_query("SELECT * FROM works LIMIT {$huuha},{$baitren_mottrang} ") or die(mysql_error());
        ?>
        <table border="1px">
            <tr >                                   
                <td>name</td>
                <td>company_name</td>
                <td>description</td>
                <td> Img </td>
                <td> Edit </td>


            </tr>
            <?php while ($info = mysql_fetch_array($result)) {
                ?>
                }
                <tr>
                    <td><?php echo $info['id']; ?></td>
                    <td><?php echo $info['company_name']; ?></td>

                    <td><?php echo substr($info['description'], 0, 100); ?></td>
                  <td><img src="<?php echo $info['image']; ?>" width="200px "></td>
                  <td> ... </td>
                </tr>
            <?php if (isset($_SESSION["id"]) && $_SESSION["id"] == 0): ?>
                    <td> <img src="<?php echo $info['image']; ?>"width="200px"></td>
                    <td> <a href="upload.php?id=<?php echo $info['id']; ?>">Edit</a>
                        <a href="view.php?id=<?php echo $info['id']; ?>" >View</a>



                    </td>
            <?php endif; ?>




                }

                <?php
            }

            if ($max > 0) {
                $prev = $page - 1;
                $next = $page + 1;
                $sotrang = $max;
                if (!isset($_GET['page']))
                    $page = 1;
                else
                    $page = $_GET['page'];
                settype($page, "int");
                if ($page != 0 && $page > 0) {
                    echo "<a href='index.php?page=1'> Firt </a>";
                    echo ' - ';
                }
                if ($page > 1) {
                    echo "<a href='index.php?page={$prev}'> Prev </a>";
                    if ($page != $sotrang)
                        echo ' - ';
                }
                if ($page > 0 && $page + 5 < $sotrang) {
                    for ($i = $page; $i <= $page + 5; $i++) {
                        if ($i != $page) {
                            echo '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . $i . '">' . $i . '</a>';
                        } else {
                            echo '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . $i . '" class="active">' . $i . '</a>';
                        }
                        echo ' - ';
                    }
                }
                if ($page < $sotrang) {
                    echo "<a href='index.php?page={$next}'> Next </a>";
                    if ($page != $sotrang - 1)
                        echo ' - ';
                }
                if ($page != $sotrang && $page < $sotrang - 1) {
                    echo "<a href='index.php?page={$sotrang}'> Last </a>";
                }
            }
        }

    }
    ?>

</table>